home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / passw11.zip / PASSWORD.ASM < prev    next >
Assembly Source File  |  1992-11-13  |  6KB  |  243 lines

  1. ;   Program: password.sys
  2. ;   Author:  Christoph Christ
  3. ;   Purpose: Implements input of an Password in the config.sys File
  4. ;   Date:    1.11.92
  5. ;   Version: 1.01
  6. ;   USE:
  7. ;     Insert as the first Command in Config.sys the following line:
  8. ;
  9. ;       DEVICE=PASSWORD.SYS
  10.  
  11. TITLE Password
  12.  
  13. .8086
  14.  
  15. StrStart  EQU  1   ; MSDOS - kompatible Einleseroutine ohne Echo
  16.  
  17. PushAll Macro
  18.   push ax
  19.   push bx
  20.   push cx
  21.   push dx
  22.   push si
  23.   push di
  24.   push bp
  25.   push ds
  26.   push es
  27. EndM
  28.  
  29. PopAll Macro
  30.   pop es
  31.   pop ds
  32.   pop bp
  33.   pop di
  34.   pop si
  35.   pop dx
  36.   pop cx
  37.   pop bx
  38.   pop ax
  39. EndM
  40.  
  41.  
  42. CODE Segment byte public
  43. public Password
  44. Assume cs: Code, ds: Code, SS:Code
  45.  
  46. ORG 0
  47.  
  48. ; Device header ------------------------------------------------
  49.  
  50. Next_Driver    DD -1
  51. Attributes     DW 0
  52. StrategyProc   DW OFFSET Strategy
  53. CommandsProc   DW OFFSET Commands
  54. Device_Name    DB 'PASSWORD'
  55.  
  56. ; Variables ----------------------------------------------------
  57.  
  58. Input          DB 40, 0, 40 dup(?)     ;
  59. Password       DB 5, 'FWFWQ', 35 dup(?),'$'; "GUEST" is standard
  60.  
  61.  
  62. Copyright      DB 'Password Protection V1.0 (c) by Christoph Christ 1.11.1992',13,10
  63.                DB '----------------------------------------------------------',13,10,'$'
  64. Prompt         DB 13,10, 'Please enter your password: $'
  65. RepeatPrompt   DB 13,10, 'Code invalid - Repeat login',13,10,'$'
  66. NoAccessMsg    DB 13,10, 'No Access - System stopped',13,10,10,10,'$'
  67. AccessMsg      DB 13,10, 'Access - System can boot',13,10,10,10,'$'
  68.  
  69. Params         DD 0                    ; Adresse des Requestheaders
  70. Counter        DB 3
  71. Passed         DB 1                    ; 0=True 1=False
  72. ; Request header -----------------------------------------------
  73.  
  74. Request struc
  75.    Len         db 0
  76.    Unit        db 0
  77.    CommandCode db 0
  78.    Status      dw 0
  79.    CountUnits  db 0
  80.    EndAdress   dd 0
  81.    BIOS_Param  dd 0
  82.    DriveNr     db 0
  83.    ConfigError dw 0
  84. Request ends
  85.  
  86. ; Strategy Entry Point ----------------------------------------
  87.  
  88.  
  89. Strategy proc
  90.          mov Word Ptr Params, bx       ; Request-Header is handled here
  91.          mov Word Ptr Params + 2, es
  92. Strategy endp
  93.  
  94. ; Commands Entry Point ----------------------------------------
  95.  
  96. Commands proc
  97.          cmp cs:passed, 0
  98.          je Exit
  99. Start:   PushAll                       ; Save all processor-registers 
  100.          mov ax, cs                    ; Set Datasegment to Codesegment
  101.          mov ds, ax
  102.          call Encrypt
  103.          mov dx, offset Copyright
  104.          call PrintStr
  105. Read:
  106.          mov dx, offset Prompt
  107.          call PrintStr
  108.          call InputStr
  109.          Call ScanLine
  110.          jz OK
  111.          cmp Counter, 0
  112.          je NoAccess
  113.          mov dx, offset RepeatPrompt
  114.          call PrintStr
  115.          dec counter
  116.          jmp Read
  117.  
  118. OK:                                    ; Output Access Mesage and boot
  119.          mov dx, offset AccessMsg
  120.          call PrintStr
  121.          mov passed, 0
  122.          PopAll                        ; Get all previous saved Registers
  123. Exit:    retf                          ; far return to DOS
  124.  
  125. NoAccess:
  126.          mov dx, offset NoAccessMsg
  127.          call PrintStr
  128.          mov al, 09h                   ; Set Keyboardinterrupt to IRET
  129.          mov ah, 25h                   ; mov dx, offset Int09
  130.          int 21H
  131. here:    jmp here                      ; won't terminate
  132.          retf
  133. Commands endp
  134.  
  135. Encrypt  proc
  136.          mov di, 1                     ; start compare from Byte 1 (not 0!!)
  137.          mov cl, byte ptr Password     ; Load length to encrypt the Password
  138.          cbw                           ; cx := Length(Password)
  139.          mov bx, offset Password       ; bx := ofs(Password) ds := Seg(P.W.)
  140. L1:      mov al, cs:[bx + di]          ; al := Password[di]
  141.          mov dx, di                    ; al := al xor di
  142.          xor al, dl
  143.          mov cs:[bx + di], al          ; Password[di] := sl
  144.          inc di                        ; next character from String
  145.          loopnz L1
  146.          ret
  147. encrypt  endp
  148.  
  149. printstr proc
  150.          mov ah, 09H
  151.          int 21H                       ; and output
  152.          ret
  153. printstr endp
  154.  
  155. InputStr proc
  156.          mov ax, cs
  157.          mov es, ax
  158.          mov bx, offset Input
  159.          call ReadString
  160.          ret
  161. InputStr endp
  162.  
  163. ScanLine proc
  164.          mov cl, Byte ptr Password    ; Stringlength of Password
  165.          xor ch, ch
  166.          mov ax, cs
  167.          mov es, ax
  168.          mov ds, ax
  169.          mov di, offset Password +1   ; load Strings to compare
  170.          mov si, offset Input + 2
  171.          cld
  172.          repe cmpsb                   ; if ZF=0 then Input <> Password
  173.          ret
  174. ScanLine endp
  175.  
  176. ReadString proc
  177.         xor di, di
  178.         mov dl, byte ptr es:[bx + di] ; dl := Maximale Länge
  179.         xor dh, dh
  180.         inc di
  181.         mov byte ptr es:[bx + StrStart], 0  ; Stringlänge := 0
  182.         inc di
  183.  
  184. @Repeat:
  185.         call @GetChar                 ; einlesen
  186.         cmp al, 32
  187.         jae @Weiter                   ; erlaubt #32 .. #255
  188.         cmp al, 13                    ; return ?
  189.         je @quit
  190.         cmp al, 8                     ; Backspace
  191.         jne @Repeat
  192.         call @Backspace
  193.         jmp @repeat
  194. @Weiter:
  195.         cmp di, dx                    ; di > MaxStrLen
  196.         je  @quit
  197.         call @AddChar
  198.         call @DisplayStern
  199.         jmp @Repeat
  200. @BackSpace:
  201.         cmp di, 2                     ; wenn am puffer beginn nicht zurück
  202.         jb @Repeat
  203.         dec di
  204.         mov ax, di                    ; Stringl. wegen längenbyte noch verkürzen
  205.         dec ax
  206.         mov byte ptr es:[bx + StrStart], al  ; Länge speichern
  207.         mov al, 8                     ; Bildschirm-löschen
  208.         call @OutChar
  209.         mov al, 32
  210.         call @OutChar
  211.         mov al, 8
  212.         call @OutChar
  213.         ret
  214. @AddChar:
  215.         mov byte ptr es:[bx + di], al
  216.         mov ax, di
  217.         mov byte ptr es:[bx + StrStart], al
  218.         inc di
  219.         ret
  220. @DisplayStern:
  221.         mov al, '*'
  222.         call @OutChar
  223.         ret
  224.  
  225. @OutChar:
  226.         push bx
  227.         mov ah, 0Eh
  228.         mov bx, 0007h
  229.         int 10h
  230.         pop bx
  231.         ret
  232. @GetChar:
  233.         mov ah, 08h
  234.         int 21h
  235. @Quit:  ret
  236. ReadString endp
  237.  
  238. Int09  proc
  239.        iret
  240. Int09  endp
  241.  
  242. CODE ends
  243. end